<!-- HTML for static distribution bundle build -->
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>力谱云内部管理系统API</title>
  <link rel="stylesheet" type="text/css" href="/swagger/swagger-ui.css">
  <link rel="shortcut icon" href="/favicon.ico"/>
  <link rel="icon" href="/favicon.ico"/>
  <style>
    html {
      box-sizing: border-box;
      overflow: -moz-scrollbars-vertical;
      overflow-y: scroll;
    }

    *,
    *:before,
    *:after {
      box-sizing: inherit;
    }

    body {
      margin: 0;
      background: #fafafa;
    }
  </style>
</head>

<body>
<div id="swagger-ui"></div>
<script src="/swagger/swagger-ui-bundle.js"></script>
<script src="/swagger/swagger-ui-standalone-preset.js"></script>
<script>

  window.onload = function () {
    // Build a system
    const ui = SwaggerUIBundle({
      url: "",
      dom_id: '#swagger-ui',
      deepLinking: true,
      presets: [
        SwaggerUIBundle.presets.apis,
        SwaggerUIStandalonePreset
      ],
      plugins: [
        SwaggerUIBundle.plugins.DownloadUrl
      ],
      layout: "StandaloneLayout"
    });
    window.ui = ui;
    initializeBaseUrl()
  };
  const baseUrl = window.location.protocol + "//" + window.location.host;

  function selectChange() {
    const apiSelect = document.getElementById("api-select");
    const selectValue = apiSelect.options[apiSelect.selectedIndex].value;
    const jsonApiUrl = baseUrl + selectValue;
    window.ui.specActions.updateUrl(jsonApiUrl);
    window.ui.specActions.download(jsonApiUrl)
  }

  function initializeBaseUrl() {
    fetch("/swagger-resources", {
      credentials: 'include',
      headers: {
        'Content-Type': 'application/json',
        'X-Requested-With': 'XMLHttpRequest'
      },
    }).then((response) => {
      return response.json()
    }).then(json => {
      const top_select = document.createElement("select");
      json.map(function (v, k) {
        const option = document.createElement("option");
        option.setAttribute("value", v.location);
        option.innerHTML = v.name;
        if (k === 0) {
          option.setAttribute("selected", true);
          window.ui.specActions.updateUrl(baseUrl + v.location);
          window.ui.specActions.download(baseUrl + v.location)
        }
        top_select.appendChild(option)
      });
      top_select.setAttribute("id", "api-select");
      top_select.setAttribute("style", "width:30%");
      top_select.setAttribute("onChange", "selectChange()");
      const fromInputBox = document.getElementsByClassName("download-url-wrapper");
      fromInputBox[0].insertBefore(top_select, fromInputBox[0].childNodes[1])
    })

  }


</script>
</body>

</html>
